#ifndef NANO_MESSAGE_H
#define NANO_MESSAGE_H
#include "../protocol/protocol.h"

#include <godot_cpp/core/binder_common.hpp>
#include <godot_cpp/classes/ref_counted.hpp>
#include <godot_cpp/variant/packed_byte_array.hpp>
namespace godot
{
class NanoMessage : public RefCounted {
    GDCLASS(NanoMessage, RefCounted)
protected:
    static void _bind_methods();
public:
    enum MessageType {
        TYPE_REQUEST = 0,
        TYPE_NOTIFY = 1,
        TYPE_RESPONSE = 2,
        TYPE_PUSH = 3
    };
public:
    uint32_t id;
    MessageType type;
    bool compress_route;
    String route;
    PackedByteArray body;
	bool valid = true;//the message from decode have this
public:
    bool is_valid() const {
        return valid;
	}
public:
    void set_id(uint32_t p_id) {
        id = p_id;
	}
    uint32_t get_id() const {
        return id;
    }
    void set_type(MessageType p_type) {
        type = p_type;
    }
    MessageType get_type() const {
        return type;
    }
    void set_compress_route(bool p_compress_route) {
        compress_route = p_compress_route;
    }
    bool get_compress_route() const {
        return compress_route;
    }
    void set_route(const String &p_route) {
        route = p_route;
    }
    String get_route() const {
        return route;
    }
    void set_body(const PackedByteArray &p_body) {
        body = p_body;
    }
    PackedByteArray get_body() const {
        return body;
	}
public:
    NanoMessage() = default;
    void initNanoMessage(Protocol::Message msg) {
        id = msg.id;
        type = static_cast<MessageType>(msg.type);
        compress_route = msg.compressRoute;
        route = String(msg.route.c_str());
        if (!msg.body.empty()) {
            body.resize(msg.body.size());
            for (size_t i = 0; i < msg.body.size(); i++) {
                body[i] = msg.body[i];
            }
        }
    }

};
}
VARIANT_ENUM_CAST(godot::NanoMessage::MessageType);

#endif